package com.insigma.business.qrcode.common.template;


import com.insigma.business.qrcode.common.vo.BaseResponse;

public class BasePagingResponse<T> extends BaseResponse<T> {
    private static final long serialVersionUID = 1L;
    public static final String ASC = "asc";
    public static final String DESC = "desc";
    private int pageNo = 1;
    private int pageSize = 20;
    private long totalCount = -1L;

    private Integer allCount;

    private Object extra;

    private Object head;

    public BasePagingResponse() {
    }

    public BasePagingResponse(int pageNo) {
        this.pageNo = pageNo;
    }

    public BasePagingResponse(int pageNo, int pageSize) {
        this.pageSize = pageSize;
        this.pageNo = pageNo;
    }

    public int getPageNo() {
        return this.pageNo;
    }

    public int getPageSize() {
        return this.pageSize;
    }

    public int getFirst() {
        return (this.pageNo - 1) * this.pageSize;
    }

    public int getLast() {
        int last = this.pageNo * this.pageSize;
        return (long)last > this.totalCount ? (int)this.totalCount : last;
    }

    public long getTotalCount() {
        return this.totalCount;
    }

    public void setTotalCount(long totalCount) {
        this.totalCount = totalCount;
    }

    public long getTotalPages() {
        if (this.totalCount < 0L) {
            return -1L;
        } else {
            long count = this.totalCount / (long)this.pageSize;
            if (this.totalCount % (long)this.pageSize > 0L) {
                ++count;
            }

            return count;
        }
    }

    public boolean isHasNext() {
        return (long)(this.pageNo + 1) <= this.getTotalPages();
    }

    public int getNextPage() {
        return this.isHasNext() ? this.pageNo + 1 : this.pageNo;
    }

    public boolean isHasPre() {
        return this.pageNo - 1 >= 1;
    }

    public int getPrePage() {
        return this.isHasPre() ? this.pageNo - 1 : this.pageNo;
    }

    public int getLastPage() {
        int totalPage = (int)(this.totalCount / (long)this.pageSize);
        totalPage = this.totalCount % (long)this.pageSize > 0L ? totalPage + 1 : totalPage;
        return totalPage == 0 ? 1 : totalPage;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getAllCount() {
        return allCount;
    }

    public void setAllCount(Integer allCount) {
        this.allCount = allCount;
    }

    public Object getExtra() {
        return extra;
    }

    public void setExtra(Object extra) {
        this.extra = extra;
    }

    public Object getHead() {
        return head;
    }

    public void setHead(Object head) {
        this.head = head;
    }
}
